package me.zzde.wallpaper.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.List;

import me.zzde.wallpaper.R;
import me.zzde.wallpaper.model.UserWallpaper;

/**
 * 右侧主界面ListView的适配器
 *
 * @author Administrator
 */
public class WallPaperAdapter extends BaseAdapter {

    private Context context;
    private List<UserWallpaper> userWallpapers;

    public WallPaperAdapter(Context context, List<UserWallpaper> userWallpapers) {
        this.context = context;
        this.userWallpapers = userWallpapers;
    }

    @Override
    public int getCount() {
        if (userWallpapers != null) {
            return userWallpapers.size();
        } else {
            return 10;
        }
    }

    @Override
    public Object getItem(int position) {
        return userWallpapers.size();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHold holder = null;
        if (view == null){
            holder = new ViewHold();
            view = View.inflate(context, R.layout.item_wallpaper, null);
            holder.wallpaper_title = view.findViewById(R.id.wallpaper_title);
        }else{
            holder = (ViewHold) view.getTag();
        }
        holder.wallpaper_title.setText(userWallpapers.get(i).getWallpaperTitle());
        Log.i("tttt", userWallpapers.get(i).getWallpaperTitle());

        return view;
    }

    private static class ViewHold {
        private TextView wallpaper_title;
    }

}
